﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="ProductCategory.aspx.cs" Inherits="Enterprise.Admin.ProductCategory" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../Content/Widget/fancyBox/jquery.fancybox.css" rel="stylesheet" charset="utf-8" />
    <script src="../Content/Widget/fancyBox/jquery.fancybox.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.mousewheel.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.easing.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/AjaxFileUploader/ajaxfileupload.js" charset="utf-8" type="text/javascript"></script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="tree_list"></table>
    <div id="edit_product_categroy">
        <form id="edit_product_categroy_form">
            <p>
                <label>分类名称</label>
                <input type="text" name="CoName" value="" />
                <input type="hidden" name="CoProductCategoryId" id="edit_product_categroy_id" />
            </p>
            <p class="en-us">
                <label>分类名称(En)</label>
                <input type="text" name="CoNameEn" value="" />

            </p>
            <p>
                <label>图片：</label>
                <span id="edit_upload_box">
                    <input type="file" id="edit_upload" name="Filedata" /></span>（宽：435，高：589）
            </p>
            <p>
                <label>父级分类</label>
                <u id="edit_parent_categroy_name"></u>
            </p>
            <p>
                <label>排序</label>
                <input type="text" name="CoSort" value="" />
            </p>

        </form>
    </div>
    <div id="add_product_categroy">
        <form id="add_product_categroy_form">
            <p>
                <label>分类名称</label>
                <input type="text" name="CoName" value="" />
            </p>
            <p class="en-us">
                <label>分类名称(En)</label>
                <input type="text" name="CoNameEn" value="" />

            </p>
            <p>
                <label>图片：</label>
                <span id="add_upload_box">
                    <input type="file" id="add_upload" name="Filedata" /></span>（宽：435，高：589）
            </p>
            <p>
                <label>父级分类</label>
                <u id="add_parent_categroy_name"></u>
                <input type="hidden" name="CoParentId" id="add_parent_id" />
            </p>
            <p>
                <label>排序</label>
                <input type="text" name="CoSort" value="" />
            </p>

        </form>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            var treegrid = $('#tree_list').treegrid({
                url: 'Handle/GetProductCategoryTreeJson.aspx',
                idField: 'id',
                treeField: 'CoName',
                title: '产品分类列表',
                rownumbers: true,
                fitColumns: true,
                autoRowHeight: false,
                remoteSort: false,
                fit: true,
                nowrap: true,
                striped: true,
                collapsible: true,
                singleSelect: false,
                onSelect: function (rowData, index) {
                    $('#tree_list').treegrid("unselectAll");
                    selectChange(rowData.id, rowData.CoName);
                },
                onSelectAll: function (rowData, index) {
                    $('#tree_list').treegrid("unselectAll");
                },

                onUnselectAll: function (rowData, index) {
                    selectChange('', '根路劲');
                },

                onUnselect: function (rowData, index) {
                    $('#tree_list').treegrid("unselectAll");
                    selectChange('', '根路劲');
                },
                onLoadSuccess: function () {
                    $(".fancybox_image").fancybox({
                        'transitionIn': 'none',
                        'transitionOut': 'none',
                        'titlePosition': 'over'
                    });
                },
                columns: [[

                        { title: '类型名称', field: 'CoName', width: 280 },
                          { title: '类型名称(En)', field: 'CoNameEn', width: 280 },
                       {
                           field: 'CoIsSystem', title: '系统项', width: 100, align: 'center',
                           formatter: function (value, rec) {
                               return value == "True" ? '是' : '否';
                           }
                       },
                       { title: '序号', field: 'CoSort', align: 'center', width: 100 },
                       { title: '深度', field: 'CoDepth', align: 'center', width: 60 },
                                            {
                                                field: 'CoNormalImage', title: '图片', width: 80, align: 'center',
                                                formatter: function (value, rowData) {
                                                    return '<a class="fancybox_image" href="../upload/ProductCategory/' + rowData.CoNormalImage + '"></a>';
                                                }
                                            },
                           {
                               title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec, index) {
                                   return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';

                               }
                           },
                                 {
                                     title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec, index) {
                                         return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';

                                     }
                                 },
                                    {
                                        title: '子类', field: 'OpAddChild', width: 80, align: 'center', formatter: function (value, rec, index) {
                                            return '<a href="javascript:void(0);" mce_href="#" onclick="add(\'' + rec.id + '\',\'' + rec.CoName + '\')">添加</a> ';

                                        }
                                    }
                ]],
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        var selectData = $('#tree_list').treegrid('getSelected');
                        if (selectData == null) {
                            add('', '根路劲');
                        } else {
                            add(selectData.id, selectData.CoName);
                        }

                    }

                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#tree_list').treegrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }

                    }

                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#tree_list').treegrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }

                    }

                }]
            });
            $('#add_product_categroy').dialog({
                width: 500,
                height: 290,
                title: '添加产品分类',
                closed: true,
                closable: true,
                tools: [{
                    iconCls: 'icon-save',
                    handler: function () {
                        addSave();
                    }
                }], buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_product_categroy').dialog('close');
                    }
                }]


            });
            $('#edit_product_categroy').dialog({
                width: 500,
                height: 290,
                title: '产品分类修改',
                closed: true,
                closable: true,
                tools: [{
                    iconCls: 'icon-save',
                    handler: function () {
                        editSave();
                    }
                }], buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_product_categroy').dialog('close');
                    }
                }]
            });
            $('#edit_product_categroy_form').form({
                onBeforeLoad: function () { $('#edit_product_categroy').dialog("close"); },
                onLoadSuccess: function (data) {
                    $('#edit_product_categroy').dialog("open");
                    $('#edit_parent_categroy_name').html(data.CoParentName);
                },
                onLoadError: function () { $('#edit_product_categroy').dialog("open"); }
            });
        });

        function edit(id) {
            $('#edit_product_categroy_form')[0].reset();
            $('#edit_product_categroy_form').form('load', 'Handle/GetproductCategoryDetailJson.aspx?id=' + id);
            $('#edit_product_categroy').dialog('open');

        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/DeleteProductCategory.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#tree_list").treegrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }
            });

        }

        function selectChange(parentId, parentName) {
            $('#add_parent_categroy_name').html(parentName);
            $('#add_parent_id').val(parentId);
        }
        function add(parentId, parentName) {
            $('#add_product_categroy_form')[0].reset();
            selectChange(parentId, parentName);
            $('#add_product_categroy').dialog('open');
        }

        function addSave() {
            $.ajaxFileUpload({
                type: "POST",
                fileElementId: 'add_upload',
                dataType: 'json',
                url: "Handle/AddProductCategory.aspx",
                data: $("#add_product_categroy_form").serializeObject(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $('#tree_list').treegrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '修改失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        function editSave() {
            $.ajaxFileUpload({
                type: "POST",
                fileElementId: 'edit_upload',
                dataType: 'json',
                url: "Handle/EditproductCategory.aspx",
                data: $("#edit_product_categroy_form").serializeObject(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $('#tree_list').treegrid("reload");
                    }

                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '修改失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });

                }
            });
        }
    </script>
</asp:Content>
